<?php

	class EventNotificationBusiness {
		
		public function selectEventNotificationByEventId($eventId) {
			$dataBaseConnection = DataAccessFactory::factory('DataAccessMySQL');
			
			$dataBaseConnection->connect();
			
			$eventNotificationDataAccess = DataAccessFactory::factory('EventNotificationDataAccessMySQL');
			
			$result = $eventNotificationDataAccess->selectEventNotificationByEventId($eventId, $dataBaseConnection);
			
			$dataBaseConnection->disconnect();
			
			return $result;
		}
		
		public function selectEventNotificationByEventItemId($eventItemId) {
			$dataBaseConnection = DataAccessFactory::factory('DataAccessMySQL');
			
			$dataBaseConnection->connect();
			
			$eventNotificationDataAccess = DataAccessFactory::factory('EventNotificationDataAccessMySQL');
			
			$result = $eventNotificationDataAccess->selectEventNotificationByEventItemId($eventItemId, $dataBaseConnection);
			
			$dataBaseConnection->disconnect();
			
			return $result;
		}
		
		public function saveNotification($notification, $dataBaseConnection = null) {
			$connectionOpened = false;
			if ($dataBaseConnection == null) {
				$connectionOpened = true;
				$dataBaseConnection = DataAccessFactory::factory('DataAccessMySQL');
				$dataBaseConnection->connect();
				$dataBaseConnection->beginTransaction();
			}
			
			$eventNotificationDataAccess = DataAccessFactory::factory('EventNotificationDataAccessMySQL');
			
			$result = $eventNotificationDataAccess->saveNotification($notification, $dataBaseConnection);
			
			if ($connectionOpened) {
				if ($result == -1) {
					$dataBaseConnection->rollback();
				} else {
					$dataBaseConnection->commit();
				}
				$dataBaseConnection->disconnect();
			}
			
			return $result;
		}
		
		
	}

?>